<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$id = get_input('id');

if(dt_discard_game($id)) {
    $game = dt_get_game($id);
    $noun_user = dt_get_user_by_user_id($game->noun_id);
    $adjective_user = dt_get_user_by_user_id($game->adjective_id);
    $noun_name = $noun_user->fullname;
    $adjective_name = $adjective_user->fullname;
    $noun = $game->noun;
    $adjective = $game->adjective;
    $message = "Hey $adjective_name, $noun_name just discarded the drawing \"$adjective $noun\".";
    //dt_send_push_notification($game->adjective_id, $message, TRUE);
    //dt_send_push_notification($game->adjective_id, $message, FALSE);
    $noun = $game->noun;
    $adjective = $game->adjective;
    $noun_id = $game->noun_id;
    $games = dt_random_games($noun_id, $noun, $adjective, 2);
    if (!$games) {
        $games = array();
    } else {
        for($i = 0; $i < count($games); $i++) {
            //var_dump($games[$i]);
            //echo $games[$i]->noun_id;
            //echo $games[$i]->adjective_id;

            $noun_user = dt_get_user_by_user_id($games[$i]->noun_id);
            $adjective_user = dt_get_user_by_user_id($games[$i]->adjective_id);
            //var_dump($noun_user);
            //var_dump($adjective_user);
            if($noun_user) {
                $games[$i]->noun_fbid = $noun_user->facebook_id;
                $games[$i]->noun_name = $noun_user->fullname;
            }
            if($adjective_user) {
                $games[$i]->adjective_fbid = $adjective_user->facebook_id;
                $games[$i]->adjective_name = $adjective_user->fullname;
            }
        }
    }
    echo json_encode(export_result(200, $games));
} else {
    echo json_encode(export_result(400, array()));
}

?>
